package com.github.xaidanwang.data.upload.download.scheduler;

/**
 * @author wang yi fei
 * @date 2019/9/19 10:06
 */
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.Set;

/**
 * 抓拍通知定时任务 每 500ms 从队列中回去抓拍通知批量入库
 */
@Slf4j
@Component
public class CaptureLogSaveScheduler implements Runnable {
	@Autowired
	private RedisTemplate redisTemplate;
	@Override
	public void run() {
		try {
			log.info("延迟红包房间");
			long nowSecond = System.currentTimeMillis()/1000;
			Set<String> roomeSet = redisTemplate.opsForZSet().rangeByScore("delay_que_room_zet",nowSecond - 2,nowSecond,0,5);
			if (roomeSet.size() > 0){
				roomeSet.forEach( roomId -> {
					redisTemplate.opsForList().rightPush("read_room_set_list",roomId);
				});
			}
		}catch (Exception e){
			log.error("抓拍日志定时任务错误,原因：[{}]",e);
		}
	}
}
